/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-07-20 11:27:13
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:37:07
 */
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { LazyLoadEvent } from 'primeng/api';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { WorkFlowServiceProxy } from '@shared/service-proxies/service-proxies';
import { ProcedureChangeComponent } from './procedure-change/procedure-change.component';
import { BomComponent } from './bom/bom.component';
import { BonChangeComponent } from './bon-change/bon-change.component';

@Component({
    selector: 'app-my-approval',
    templateUrl: './my-approval.component.html',
    styleUrls: ['./my-approval.component.less']
})
export class MyApprovalComponent extends AppComponentBase {
    @ViewChild('ProcedureChangeComponent') ProcedureChangeComponent: ProcedureChangeComponent;
    @ViewChild('BonChangeComponent') BonChangeComponent: BonChangeComponent;
    @ViewChild('BomComponent') BomComponent: BomComponent;
    @ViewChild('paginator') paginator: Paginator;
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator2') paginator2: Paginator;
    @ViewChild('dataTable2') dataTable2: Table;
    detaillFlag = false;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _workFlowServiceProxy: WorkFlowServiceProxy,
    ) {
        super(injector);
    }
    title = '';
    rowdata: any;
    flag = false;
    ngOnInit() {
    }
    onChange(event) {
        if (event.index == 0 ) {
            this.getTableList();
        }else if (event.index == 1) {
            this.getSonTableList();
        }
    }
    getTableList(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this._workFlowServiceProxy.getApprovaling(
            [],
            [],
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event)
        ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
            this.primengTableHelper.totalRecordsCount = result.totalCount;
        this.primengTableHelper.records = result.items;
            this.primengTableHelper.hideLoadingIndicator();
        });
    }
    getSonTableList(event?: LazyLoadEvent) {
         if (this.primengSonTableHelper.shouldResetPaging(event)) {
            this.paginator2.changePage(0);
            return;
        } 
        this._workFlowServiceProxy.getApprovaled(
            [],
            [],
            this.primengSonTableHelper.getSorting(this.dataTable2),
            this.primengSonTableHelper.getMaxResultCount(this.paginator2, event),
            this.primengSonTableHelper.getSkipCount(this.paginator2, event)
        ).pipe(finalize(() => this.primengSonTableHelper.hideLoadingIndicator())).subscribe(result => {
            this.primengSonTableHelper.totalRecordsCount = result.totalCount;
            this.primengSonTableHelper.records = result.items;
            this.primengSonTableHelper.hideLoadingIndicator();
        });
    }
    detaillLook(row, type) {
        this.rowdata = row;
        this.title = '审批';
        if (type) {
            this.flag = true;
            if (row.menu == '规程变更管理') {
                setTimeout(() => {
                    this.ProcedureChangeComponent.show();
                }, 10);
            }
            if (row.menu == '设计bom变更管理') {
                setTimeout(() => {
                    this.BomComponent.show();
                }, 10);
            }
            if (row.menu == 'bom变更管理') {
                setTimeout(() => {
                    this.BonChangeComponent.show();
                }, 10);
            }
        } else {
            this.flag = false;
            if (row.menu == '规程变更管理') {
                setTimeout(() => {
                    this.ProcedureChangeComponent.show();
                }, 10);
            }
            if (row.menu == '设计bom变更管理') {
                setTimeout(() => {
                    this.BomComponent.show();
                }, 10);
            }
            if (row.menu == 'bom变更管理') {
                setTimeout(() => {
                    this.BonChangeComponent.show();
                }, 10);
            }
        }
    }
    rollback(row,type) {
    }
}
